
<!-- saved from url=(0053)http://www.imagemagick.org/Usage/anim_basics/#dispose -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Animation Basics -- IM v6 Examples</title>
<link rel="icon" href="http://www.imagemagick.org/Usage/img_www/favicon.ico" type="image/x-icon">
<link rel="shortcut" href="http://www.imagemagick.org/Usage/img_www/favicon.ico" type="image/x-icon">
<link rel="canonical" href="http://www.imagemagick.org/Usage/anim_basics/">
</head><body bgcolor="#B0C4DE">

<h1>ImageMagick v6 Examples -- <br>
    <img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="50" height="1">
    Animation Basics</h1>

<div align="justify">

<dl>
<dt><b>Index</b>
</dt><dt><a href="http://www.imagemagick.org/Usage/"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_left.gif" border="0" width="15" height="15"> ImageMagick Examples Preface and Index</a>
</dt><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#gif_anim"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> GIF Animations and Animation Meta-data</a>
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#dispose"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> Frame Disposal Methods</a>
    <ul>
    <li><a href="http://www.imagemagick.org/Usage/anim_basics/#none">Dispose None</a> - overlay each frame in sequence
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Dispose Previous</a> - preserve background canvas
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Dispose Background</a> - clear to background
    </li></ul>
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#study"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> Studying Animations</a>
    <ul>
    <li><a href="http://www.imagemagick.org/Usage/anim_basics/#identify">Identify</a>              - information about an animation
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#adjoin">Adjoin</a>                - splitting into individual frame images
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#coalesce">Coalesce</a>              - fill out frames completely
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#montage">Frame Montage</a>         - the "gif_anim_montage" script
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#list_info">List Information</a>      - rebuild an existing animation
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#dispose_images">Disposal Images</a>       - the GIF dispose form of the frames
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#deconstruct">Deconstruct</a>           - report areas of frame differences
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#compare">Frame Comparisons</a>     - more detailed frame differences
        <dl><dd>
        <a href="http://www.imagemagick.org/Usage/anim_basics/#compareany">Compare_Any</a>,&nbsp;
        <a href="http://www.imagemagick.org/Usage/anim_basics/#compareclear">Compare_Clear</a>,&nbsp;
        <a href="http://www.imagemagick.org/Usage/anim_basics/#compareoverlay">Compare_Overlay</a>
        </dd></dl>
    </li></ul>
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#types"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> Types of Animations</a>
    <ul>
    <li><a href="http://www.imagemagick.org/Usage/anim_basics/#coalesced">Coalesced Animations</a>
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animations</a>
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared Frame Animations</a>
    </li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#mixed">Mixed Disposal Animations</a>
    </li></ul>
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#loop"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> The End of the Loop</a>      - when an animation stops running
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#zero"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> Zero Delay Intermediate Frames</a>
</dd></dl>

These examples continue the previous example page on <a href="http://www.imagemagick.org/Usage/layers/">Layers of Multiple Images</a> but instead of layering multiple images on top
of each other to produce a single image, here we display each image for a
short period of time so as to  produce an animation of images. <p></p>

The following section provides a basic understanding of the complexities of
animations and specifically GIF animations. It looks at the basic methods used
to generate animations, and how you can study existing animations to get an
understanding of how they work. <p></p>

This is recommended reading before going further in any of the later animation
sections. <p></p>

<hr><!-- ------------------------------------------------------------------ -->

<a name="gif_anim"></a>
<h2>GIF Animations and Animation Meta-data</h2>

The default way ImageMagick handles the output of an image list is to generate
a multi-page image.  For the GIF image format, however, this takes the special
form of a 'GIF animation'.

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert -delay 100  -size 100x100 xc:SkyBlue \
          -page +5+10  balloon.gif   -page +35+30 medical.gif  \
          -page +62+50 present.gif   -page +10+55 shading.gif  \
          -loop 0  animation.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/animation.gif"><img src="./Animation Basics -- IM v6 Examples_files/animation.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

Here is a more advanced 'sparkle' example that uses a shell script
"<b><code><a href="http://www.imagemagick.org/Usage/scripts/star_field">star_field</a></code></b>".  This
script was developed from my experiments in generating <a href="http://www.imagemagick.org/Usage/advanced/#stars">random star fields</a>. <p></p>

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="" random="" script="" image="rose_sparkle.gif">
  star_field 70x46  stars1.gif
  star_field 70x46  stars2.gif
  star_field 70x46  stars3.gif
  convert rose:   -compose Screen \
          \( -clone 0 stars1.gif -composite \) \
          \( -clone 0 stars2.gif -composite \) \
          \( -clone 0 stars3.gif -composite \) \
          -delete 0 -set delay 25 -layers Optimize rose_sparkle.gif
  rm stars[123].gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/rose_sparkle.gif"><img src="./Animation Basics -- IM v6 Examples_files/rose_sparkle.gif" width="70" height="46" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

Basically three random star fields are generated, at the right size, then
overlaid onto our image, the IM built-in "<code>rose:</code>", using a
'<code><a href="http://www.imagemagick.org/Usage/compose/#screen">Screen</a></code>' alpha composition to
brighten the image with the given star patterns. The whole thing is then run
though the IM general GIF animation optimizer. <p></p>

The above may seem complex as it is using some advanced IM features I have yet
to introduce, but the result is a relatively simple, but well optimized three
frame animation. <p></p>

You can also look at some of the more complex animations that were created
using simple shell scripts for <a href="http://www.imagemagick.org/Usage/warping/#animations">Distortion
Animations</a>. <p></p>

There are a few extra IM settings which were created specifically for use in
GIF animations, and knowing about these is the first step into the world of GIF
animations... <p></p>

<table border="0" width="90%" align="center">
<tbody><tr valign="top"><td colspan="2"><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose"><b>-dispose</b></a> {method}</code></td></tr><tr><td></td>
<td align="justify">
    What the following images should do with the previous results of the GIF
    animation. Valid options are '<code>Undefined</code>', '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>', '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>', and '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>.  (See below for explanation of the settings)
    <p></p>

</td></tr>
<tr valign="top"><td><nobr><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?loop"><b>-loop</b></a> {number}</code></nobr></td>
<td align="justify">
    Number of times the GIF animation is to cycle though the image sequence
    before stopping.  It is an output 'image write' setting, so can be set
    anywhere on the command line, though only the last such setting will be
    used. <p></p>

    Usually this set by default, to zero (infinite loop), however if any image
    read in has a different value, then this setting will be set to that
    images value.  As such I recommend that you always set "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?loop">-loop</a></code>" when creating a GIF
    animation, after all the images has been read in. <p></p>

    For more information see <a href="http://www.imagemagick.org/Usage/anim_basics/#loop">The End of the Loop</a> below.
    <p></p>

</td></tr>
<tr valign="top"><td><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay"><b>-delay</b></a> {time} &nbsp;</code></td>
<td align="justify">
    Set the time delay (in 1/100th of a second) to pause after drawing the
    images that are read in or created after this setting has been defined.
    <p></p>

    You can specify a different scale for the time delay by specifying a
    '<code>x</code>' scaling (giving in ticks per second).   For example
    '<code>10x1</code>' is 10, 1 second ticks,  while '<code>10x100</code>' is
    10, one hundredth of a second ticks. <p></p>

    Basically the '<code>x</code>' is equivalent to a fraction
    '<code>/</code>' sign.  For example if you specify '<code>1x160</code>'
    will set a delay that is appropriate for 160 frames per second. <p></p>

    <table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
    <tbody><tr valign="top">
    <td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
    <td align="justify" width="100%"><font size="-1"><i>
      GIF animation delays must be specified in hundredths of a second for
      correct working, which is why that is the default time unit.  The
      '<code>x</code>' factor is used more for generating other more movie
      like formats, such a MNG's, and AVI's.
    </i></font></td></tr></tbody></table><p></p>

</td></tr>
<tr valign="top"><td colspan="2"><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?set"><b>-set</b></a> dispose {method}
<br><a href="http://www.imagemagick.org/Usage/option_link.cgi?set"><b>-set</b></a> delay {time}</code></td></tr><tr><td></td>
<td align="justify">
    While the previous option settings will set image attributes on newly
    created, or image that are read in, <i>after</i> that option is given, the
    "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?set">-set</a></code>" option is an
    operator, that will allow you set image attributes on all images that have
    <i>already</i> in the current image sequence.  This allows you to change
    the setting over a whole animation, or just a single frame, after the
    images have been loaded or modified.  <p></p>

</td></tr>
<tr valign="top"><td colspan="2"><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?page"><b>-page</b></a> {w}x{h}+{x}+{y}</code></td></tr><tr><td></td>
<td align="justify">
    This lets you set the offset position of the image about to be read in. As
    this is a setting option, it only applies the geometry you give to images
    that follow the setting.  It does not effect images already read into
    memory.  <p>

    If not given, or turned off using "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?page">+page</a></code>" the offset for the image read will be preserved.  If
    the image does not have an offset it will be positioned at
    '<code>+0+0</code>' or the top left corner of the working canvas or
    'page'. </p>

    It can also be used to define a larger working canvas, by specifying a
    width '<code>x</code>' height.  Only the width and height page setting of
    the first image in the sequence will be used to set the overall GIF
    animation canvas size, all other page size settings will be ignored when
    the animation is finally written.  When a GIF animation is read in the
    canvas size is set on all the frames in the animation. <p></p>

    MNG animations can save frame offsets, but does not save canvas sizes.
    The size of the first image defines the canvas size of the whole
    animation. <p></p>

    <table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
    <tbody><tr valign="top">
    <td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
    <td align="justify" width="100%"><font size="-1"><i>
      The GIF image format can not specify a negative offset for images on a
      canvas.  If you try to use a negative offset IM will reset it to zero
      when that image (or animation frame) is written to a GIF file. <p></p>

      Positive offsets larger than the image canvas are quite acceptable but
      may result in the image not appearing in the canvas drawing area when
      displayed.  How a GIF animation display program handles this is
      undefined.   Caution is advised.
    </i></font></td></tr></tbody></table><p></p>

</td></tr>
<tr valign="top"><td colspan="2"><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage"><b>-repage</b></a> {w}x{h}+{x}+{y}</code></td></tr><tr><td></td>
<td align="justify">
    This is exactly like "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?page">-page</a></code>" except that it is an image operator instead of a
    setting.  That means you can use this to change or reset the 'page
    geometry' of an image or animation frame that has already being read into
    memory. <p></p>

    The simpler "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage">+repage</a></code>"
    form, just resets the 'page geometry' of all images to the actual image in
    each frame in the current image sequence to a zero offset, and the images
    actual size.  This operation is vital when you are extracting the
    individual frames from an animation, (See the <a href="http://www.imagemagick.org/Usage/anim_basics/#adjoin">Adjoin
    Examples</a> below). <p></p>

    However "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage">+repage</a></code>" will
    destroy a lot of positioning information stored in each image, as such you
    should also probably extract this information into a separate file for
    later re-use.  See <a href="http://www.imagemagick.org/Usage/anim_basics/#list_info">Animation List Information</a>
    below.  <p></p>

</td></tr></tbody></table><p></p>


<h3>Important Point</h3>

DO NOT save the intermediate, animations which you are not finished
processing, directly to GIF.  You can use the IM internal format MIFF, as a
temporary file format, if you want to work on an animation in series of
separate processing steps. <p></p>

I repeat...<div align="center"><b>
     Do not use GIF as an intermediate file format, use MIFF instead
</b></div><p></p>

If you made the big mistake of saving to GIF you would have just made the
resulting animation worse, as IM would have now performed an automatic <a href="http://www.imagemagick.org/Usage/quantize/#colors">Color Quantization</a>, to reduce the number of
colors present.  Not only that but it did so on each frame completely
independently to every other frame, making any further processing,
particularly any GIF optimizations just that much harder. <p></p>

Solving this is a complex, multi-level problem, which is looked at in the next
section <a href="http://www.imagemagick.org/Usage/anim_opt/">Animation Optimization</a>. <p></p>

<hr><!-- ---------------------------------------------------------------- -->

<a name="dispose"></a>
<h2>Frame Disposal Methods</h2>

The first thing people creating GIF animation have trouble with is the
"<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" setting.  This
is not surprising as it is a complex setting.  Worse still a lot of animation
programs, including many web browsers, don't always handle the GIF disposal
meta-data setting correctly.  However using the right disposal can make a big
difference to how well your animation works and optimizes. <p></p>

The first thing to remember in ImageMagick is that almost all the special
animation options, are settings for image reading.  That is they are applied
to images that are read in, after, the setting has been given.  The "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?loop">-loop</a></code>" setting is the only one
typically used after the animation has been completed, just before the the
animation is saved. <p></p>

The basic task of  the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" defines how an image is to be removed, <i>after</i> it
has been displayed for its "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay">-delay</a></code>" time period.  That is, you need to give an image's "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" and "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay">-delay</a></code>" settings <i>before</i>
reading the image for that frame.  But the action is applied after that image
is displayed.  This is a little counter intuitive but does make sense in the
way IM operates on images.  <p></p>

If you remember this, you should have no problems. <p></p>

The 'plus' forms of these options, like most other settings in IM stops the
setting being applied to any images being read in.  That means if you don't
specify a setting, the frame image will continue to use the setting that was
read in with the image (if any). <p></p>

This can be important later when you want to read in a GIF animation for
further processing. Or when merging one GIF animation into another (the most
difficult animation technique). <p></p>


<a name="none"></a>
<h3>Dispose None <font size="-1">- each frame overlaid in sequence</font></h3>

The default "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>"
setting for GIF animations is '<code><b>Undefined</b></code>' which most
animation programs treats the same as a '<code><b>None</b></code>' disposal
setting.  Basically this tells the computer to just leave whatever is overlaid
by this specific frame.  Or more precisely, 'do nothing'. <p></p>

However please note that the whole canvas is always cleared at the end of the
animation sequence, before it loops and repeats. <p></p>

Here for example is a standard 'None dispose' animation...

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert -delay 100 -dispose None \
              -page 100x100+5+10  balloon.gif  \
              -page +35+30 medical.gif  \
              -page +62+50 present.gif  \
              -page +10+55 shading.gif  \
          -loop 0  anim_none.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/anim_none.gif"><img src="./Animation Basics -- IM v6 Examples_files/anim_none.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

This disposal technique is ideal for animations which involve no form of
transparency, such as animations drawn on a solid, or patterned background.

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert -dispose none  -delay 100 \
                -size 100x100 xc:SkyBlue +antialias \
                -fill DodgerBlue -draw 'circle 50,50 15,25' \
                -page +5+10  balloon.gif  \
                -page +35+30 medical.gif  \
                -page +62+50 present.gif  \
                -page +10+55 shading.gif  \
          -loop 0  canvas_none.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/canvas_none.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_none.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

Note that this technique can only add visible colors to an animation. It can
never actually make any part of an animation transparent again. (See <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animations</a> below). <p></p>

To also handle transparency need to use one of the other sorts of disposal
methods.  <p></p>


<a name="previous"></a>
<h3>Dispose Previous <font size="-1">- preserve background canvas</font></h3>

The '<code><b>Previous</b></code>' disposal method is relatively simple.  When
the current image is finished, return the canvas to what it looked like before
the image was overlaid.  If the previous frame image also used a
'<code>Previous</code>' disposal method, then the result will be that same as
what it was before that frame.. etc.. etc.. etc... <p></p>

For example in this animation each of the later frames will return to the very
first frame of the image, which has a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>
disposal setting, before overlaying the image associated with that frame. <p></p>

The result is a background canvas that has just each frame image overlaid
for just the duration of that image...

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert -dispose none  -delay 0 \
                -size 100x100 xc:SkyBlue +antialias \
                -fill DodgerBlue -draw 'circle 50,50 15,25' \
          -dispose previous -delay 100 \
                -page +5+10  balloon.gif  \
                -page +35+30 medical.gif  \
                -page +62+50 present.gif  \
                -page +10+55 shading.gif  \
          -loop 0  canvas_prev.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/canvas_prev.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

Note the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" method
'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' used for the first image. This is
important, otherwise the 'previous' frame will go all the way back to the
original empty canvas that was present before the first frame.  <p></p>

Also note that I used a  "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay">-delay</a></code>" of '<code>0</code>' in the above animation.  This says not
to wait before overlaying the first frame onto this 'background canvas'.
Without it you will see a short delay, showing just the canvas image with
nothing on top of it. <p></p>

Of course I need to still set a longer "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay">-delay</a></code>" for the later images, or they will appear and disappear in
the wink of an eye, and incidentally use up a lot of the viewers CPU cycles.
<p></p>

The use of the '<code>Previous</code>' disposal method can be prone to a
slight flickering, or pause in some web browsers, especially on slower
machines.  Though that is quite rarely seen these days, the flicker itself is
still present, and something I consider to be a bug.  See <a href="http://www.imagemagick.org/Usage/anim_basics/#zero">Zero Delay Frames</a> below for more specifics. <p></p>

Few animations make use of a dispose previous style of animation, the reason
is that it is very difficult for computers to optimise.  The problem is just
what frame should the computer pick to become the background image?  Simple
for us humans to figure out the best image to use, but difficult for a
computer decide.  The best background image to use in an animation may not
even be meant to be displayed, such as in the current example, and as such
may not exist in an un-optimized version of that animation. <p></p>


<a name="background"></a>
<h3>Dispose Background <font size="-1">- clear to background</font></h3>

While the first two "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" methods are relatively simple, the
'<code><b>Background</b></code>' is probably the hardest to understand. <p></p>

When the time delay is finished for a particular frame, the area that was
overlaid by that frame is cleared.  Not the whole canvas, just the area that
was overlaid.  Once that is done then the resulting canvas is what is passed
to the next frame of the animation, to be overlaid by that frames image. <p></p>

Here for example we just replace each frame with the next frame.

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert -delay 100 -dispose Background \
              -page 100x100+5+10  balloon.gif  \
              -page +35+30 medical.gif  \
              -page +62+50 present.gif  \
              -page +10+55 shading.gif  \
          -loop 0  anim_bgnd.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/anim_bgnd.gif"><img src="./Animation Basics -- IM v6 Examples_files/anim_bgnd.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

So you can see exactly what is going on, lets add an initial canvas image to
the animation, so you can see how a '<code>Background</code>' actually
'disposes' that frame from the animation display.

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert -delay 100 -dispose none \
                -size 100x100 xc:SkyBlue +antialias \
                -fill DodgerBlue -draw 'circle 50,50 15,25' \
          -dispose background \
                -page +5+10  balloon.gif  \
                -page +35+30 medical.gif  \
                -page +62+50 present.gif  \
                -page +10+55 shading.gif  \
          -loop 0  canvas_bgnd.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/canvas_bgnd.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_bgnd.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

As you can see as each overlaid frame is disposed of, that frames area is
cleared to transparency, before the next image is overlaid.  This is the
importance of this GIF disposal method as it is the only way GIF animations
can clear any pixel regardless of an animations frame history. <p></p>

The only other way to clear pixels is to use '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>' to go back to a frame in which those
pixels were clear. But that relies on knowing the history of the animation
sequence which makes it much more difficult for computers to optimize.  <p></p>

<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/expert.gif" width="23" height="26"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="17" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
  There is some thinking that rather than clearing the overlaid area to the
  transparent color, this disposal should clear it to the 'background' color
  meta-data setting stored in the GIF animation.  In fact the old
  "<code>Netscape</code>" browser (version 2 and 3), did exactly that. But
  then it also failed to implement the '<code>Previous</code>' dispose
  method correctly. <p></p>

  On the other hand the initial canvas should also be set from the formats
  'background' color too, and that is also not done.  However all modern web
  browsers clear just the area that was last overlaid to transparency, as
  such this is now accepted practice, and what IM now follows.
</i></font></td></tr></tbody></table><p></p>

<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/warning.gif" width="28" height="28"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="12" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
  Before IM version 6.2.6-1, the IM "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" and "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" operations
  did not handle animations that used '<code>Background</code>' disposal to
  make pixels transparent, as per all the major web browsers. See <a href="http://www.imagemagick.org/Usage/bugs/animation_bgnd/">Animation Bugs</a> for examples and
  details. <p></p>

  These functions however did work fine when no pixel clearing was applied
  or intended.  This has now been fixed for "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" and the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?layers">-layers</a>&nbsp;<a href="http://www.imagemagick.org/Usage/anim_opt/#optframe">OptimizeFrame</a></code>' method was created
  to replace the use of "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" as a GIF animation frame optimizing function.

</i></font></td></tr></tbody></table><p></p>

<hr><!-- ---------------------------------------------------------------- -->

<a name="study"></a>
<h2>Studying Animations</h2>

Before we can continue with the basics of GIF animation, their types,
optimizations, and handling techniques, we need some techniques for studying
existing animations. <p></p>


<a name="identify"></a>
<h3>Identify
<font size="-1">- information about and animation</font></h3>

Now an animation consists of a lot of information packed into each individual
frame.  You can see some of this information using the default IM
"<code><a href="http://www.imagemagick.org/Usage/basics/#identify">identify</a></code>" command.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="" nowarn="" out="identify_prev.txt">
  identify canvas_prev.gif
</code></pre></td></tr></tbody></table>
<table border="0" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td>
  <a href="http://www.imagemagick.org/Usage/anim_basics/identify_prev.txt"><img src="./Animation Basics -- IM v6 Examples_files/identify_prev.txt.gif" align="middle" vspace="0" hspace="0" border="0" alt="[IM Text]"></a>
</td></tr></tbody></table>
</div><p></p>

<table cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/warning.gif" width="28" height="28"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="12" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
  If you did not see output like the above your IM is a little old, and you
  really should upgrade your installed version of ImageMagick, to the latest
  version.  If you don't you will be missing out on a lot of the new
  advances in IM's handling and control of GIF animations.
</i></font></td></tr></tbody></table><p></p>

As you can see the actual image saved for the second and later frames is only
32x32 pixels, but all the frames sits on a 100x100 pixel 'virtual canvas' with
a 'virtual offset' on that larger canvas.  <p></p>

To see more of the various bits of meta-data that is present you need to use
some of the more specialzed <a href="http://imagemagick.org/script/escape.php">percent Escape Formats</a> to get IM to output it.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="" nowarn="" out="identify_prev_more.txt">
  identify -format "%f canvas=%Wx%H size=%wx%h offset=%X%Y %D %Tcs\n" \
           canvas_prev.gif
</code></pre></td></tr></tbody></table>
<table border="0" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td>
  <a href="http://www.imagemagick.org/Usage/anim_basics/identify_prev_more.txt"><img src="./Animation Basics -- IM v6 Examples_files/identify_prev_more.txt.gif" align="middle" vspace="0" hspace="0" border="0" alt="[IM Text]"></a>
</td></tr></tbody></table>
</div><p></p>

Which clearly shows not only the canvas size, image size and offset, but also
the disposal and time delays used for each individual frame.  Note how the
first frame has the different disposal and time delay that was needed for
proper use of the later '<a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a>' disposal method.
<p></p>


<a name="adjoin"></a>
<h3>Adjoin
<font size="-1">- splitting an animation into frames</font></h3>

Now as you saw above, ImageMagick will by default try to save multiple images
into one file if that file format allows it.  However as discussed in <a href="http://www.imagemagick.org/Usage/files/#write_list">Writing a Multi-Image List</a> IM will let you
use the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?adjoin">+adjoin</a></code>" setting
to tell it to save each image to disk as a separate individual image. <p></p>

For example, here we read in one of the GIF animations and output the individual
frame images in the animation sequence.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert canvas_prev.gif -scene 1 +adjoin  frame_%03d.gif
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/frame_001.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_001.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/frame_002.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_002.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/frame_003.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_003.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/frame_004.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_004.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/frame_005.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_005.gif" width="100" height="100" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
</div><p></p>

If you were to examine the actual images above you will find that although
most web browsers show a larger 100x100 area, on which each sub-frame appears.
In fact most of the actual images show are really only just 32x32 pixels, just
as show in the previous 'identify' commands above. <p></p>

That is most of the area is just a canvas on which nothing is drawn, known as
the images 'page geometry' or 'virtual canvas'. The first
image of the animation defines that larger 'canvas' and every other frame
defines an 'offset' position on this larger canvas.  <p></p>

This extra information is preserved in the frames that was saved by the
"<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?adjoin">+adjoin</a></code>" setting.  As
as such you can easilly re-build the GIF animation.  Not only is the page
information preserved in each separate frame image, but also any delay,
looping and GIF dispose settings, is also preserved. <p></p>

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr valign="top"><td width="100%" align="justify">

This means that to rebuild the animation you only need to read all the images
in.

<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert frame_???.gif  anim_rebuilt.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/anim_rebuilt.gif"><img src="./Animation Basics -- IM v6 Examples_files/anim_rebuilt.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

Sometimes however you don't want to preserve this page geometry information.
For example if you want to use the individual frames for other projects.  You
can reset the page size and offset using the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage">+repage</a></code>" option, to remove the
'virtual canvas' information, leaving just the actual image. <p></p>

<br>

Normally when extracting animation sub-images you also generally reset the
images delay and dispose settings too to ensure they don't interfer with the
editing and display. <p></p>

For example  here I remove the unwanted virtual canvas and offset and reset
the timing delays and disposals.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert canvas_prev.gif  +repage  -set delay 0   -set dispose None \
          +adjoin  repage_%03d.gif
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/repage_000.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_000.gif" width="100" height="100" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/repage_001.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_001.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/repage_002.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_002.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/repage_003.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_003.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/repage_004.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_004.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
</div><p></p>

Of course if you junk that meta-data, you need some way of recording and
editing that data.  See <a href="http://www.imagemagick.org/Usage/anim_basics/#list_info">Animation List Information</a>
(below) for a script that extracts both the sub-images and saves the animation
meta-data, in a form that can be used to re-build the animation. <p></p>

<a name="coalesce"></a>
<h3>Coalesce
<font size="-1">- fill out frames completely</font></h3>

Viewing an animation in the form of the sub-frames, however is usually not very
useful, in a typical animation.  <p></p>

For one thing, a highly optimized animation can consist of lots of very small
parts, without any visual indication of how they fit together.  It can also
have a lot of other 'noise' that was added for <a href="http://www.imagemagick.org/Usage/anim_opt/#compress_opt">Compression Optimization</a> to reduce the
overall file size of the animation. <p></p>

For example, it is very difficult to figure out what this animation actually
did, just by looking at the individual sub-frames of the animation.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert script_k.gif  +repage  +adjoin  script_k_%02d.gif
</code></pre></td></tr></tbody></table>
<nobr>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_00.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_00.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_01.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_01.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_02.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_02.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_03.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_03.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_04.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_04.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_05.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_05.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_06.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_06.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_07.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_07.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_08.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_08.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_09.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_09.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_10.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_10.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
</nobr>
</div><p></p>

The "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>"
operation basically converts an image into exactly what the animation should
look like after the previous frame has been correctly <a href="http://www.imagemagick.org/Usage/anim_basics/#dispose">disposed</a>, and the next sub-frame overlaid. <p></p>

That is instead of an animation sequence where each frame only represents the
overlaid changes to the previous 'disposed' frame. This operator creates a
complete view of the animation at each point, a bit like a true film strip,
rather than an animation sequence. Such a sequence, known as a <a href="http://www.imagemagick.org/Usage/anim_basics/#coalesced">Coalesced Animation</a> is much easier to study, edit,
modify and re-optimize. <p></p>

Here for example will generate a montage of the same 'confusing' animation
sequence I showed above, but this time we'll "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" the sequences, so
you can see what is really happening.

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  montage script_k.gif -coalesce \
          -tile x1 -frame 4 -geometry '+2+2' \
          -background none -bordercolor none coalesce_k_montage.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k.gif" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><div align="center">
  <a href="./Animation Basics -- IM v6 Examples_files/coalesce_k_montage.gif"><img src="./Animation Basics -- IM v6 Examples_files/coalesce_k_montage.gif" align="middle" vspace="5" hspace="10" border="0" alt="[IM Output]"></a>
</div><p></p>

As you can see the result is like a film strip of the animation, allowing you
to clearly see how the previous pieces fit together to form a hand drawn
letter 'K'. <p></p>

As of  IM version 6.2.6, the "<code>montage</code>" command understood the
use of "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>",
allowing you to create 'film strip' like image of the animation frames,
exactly as shown above. This version also contained fixes for coalesce, and
any GIF animation work should be at least this version (or better still the
latest version). <p></p>

<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
  An even better montage technique for examining animations is given in the
  next example section.
</i></font></td></tr></tbody></table><p></p>

The "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" setting of
a <i>coalesced image sequence</i> is actually irrelevant, in a <a href="http://www.imagemagick.org/Usage/anim_basics/#coalesced">Coalesced Animation</a>.  However for users piece of mind
the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" operator
will set the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>"
setting of each frame to either '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' or
'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>' as appropriate, so that
the coalesced image sequence will continue to animate correctly (as shown
above).  <p></p>

<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/expert.gif" width="23" height="26"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="17" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
  A frame with a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>'
  disposal means the next frame needed to clear at least one or more pixels,
  to be displayed correctly.  <p></p>

  As such animations in which "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" added a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>' dispose, means that the animation can not be
  saved as a simple <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animation</a> (see below).
  <p></p>

  Technically, you can set all dispose settings of a coalesced image
  sequence to either '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>' or
  '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>' to generate a <a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared Frame Animation</a> (see below). Though not all
  animations will optimize well in that form.

</i></font></td></tr></tbody></table><p></p>

Their are also some non-animation uses of the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" operator. See <a href="http://www.imagemagick.org/Usage/layers/#coalesce">Coalesce, and Progressive Flattening</a>
examples of these uses.  <p></p>

<br>

<a name="montage"></a>
<h3>Animation Frame Montage
<font size="-1">- the "gif_anim_montage" script</font></h3>

While "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?adjoin">+adjoin</a></code>" operator
will let you extract the actual images from an animation and "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" will let you see the
resulting frames of the animation, both methods leave out a lot of information
about the animation. <p></p>

By using some very careful manipulation of the animation images, you can
display the frames so as to show not only the actual frames, but also the
placement of those frames on the larger canvas.  Here is one such method of
displaying an animation.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert -dispose Background   script_k.gif  -matte \
          -compose Copy -bordercolor black -border 1x1 -compose Over \
          -coalesce  -bordercolor none   -frame 4x4+2+2 \
          -bordercolor none -border 2x2 +append  script_k_parts.gif
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_parts.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_parts.gif" align="middle" vspace="2" hspace="5" border="0" alt="[IM Output]"></a>
</div><p></p>

Here you can clearly see how the animation works. Each sub-frame image is
positioned so as to add to all the previous overlays. The result is a slowly
growing picture.  Each frame is also a lot smaller than the 'virtual canvas'
on which it is positioned. <p></p>

I use this display technique a lot during the development and debugging of GIF
animations, as such I converted it into a shell script "<b><code><a href="http://www.imagemagick.org/Usage/scripts/gif_anim_montage">gif_anim_montage</a></code></b>", and
expanded it to also list some of the details above each frame in the
animation.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  gif_anim_montage   script_k.gif   script_k_frames.gif
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_frames.gif" align="middle" vspace="2" hspace="5" border="0" alt="[IM Output]"></a>
</div><p></p>

Note the variations in the timings used in various frames, to pause as if the
pen is being lifted from the page and repositioned. Animations with variable
timing can be some of the most interesting, but also more difficult to handle,
as you will see in later IM Example pages. <p></p>

The "<code><a href="http://www.imagemagick.org/Usage/scripts/gif_anim_montage">gif_anim_montage</a></code>"
script also the special option '<code>-u</code>' which will also underlay a
semi-transparent copy of the coalesced animation.  This lets you see how the
new sub-frames modifies the displayed animation.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  gif_anim_montage  -u  script_k.gif  script_k_frames.png
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_frames.png"><img src="./Animation Basics -- IM v6 Examples_files/script_k_frames.png" align="middle" vspace="2" hspace="5" border="0" alt="[IM Output]"></a>
</div><p></p>

Of course this has semi-transparent pixels so a 'PNG' image format was needed,
OR you could use one of the many 'background' options that script also
provides, allowing you to use GIF or even JPEG formats for the resulting
summery image of the animation.  <p></p>

Other options, lets you define the number of rows or columns to use, as well
as set various non-transparent backgrounds, or use a red box rather than
the default black. <p></p>

This script will be used a lot during the next few pages of IM Examples.
Suggestions and comments are welcome. <p></p>

<br>

<a name="list_info"></a>
<a name="sequence"></a> <!-- depreciate -->
<h3>Animation List Information
<font size="-1">- options used to build an animation</font></h3>

As I noted,  using "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?adjoin">+adjoin</a></code>" and "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>", as well as "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage">+repage</a></code>", are all useful methods of extracting and looking at GIF
animations. However they all destroy information about the original animation
in the process. <p></p>

You can see this extra information on framing, time delays, frame dispose,
etc., using the  IM "<code>identify</code>" command with a "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?verbose">-verbose</a></code>" option.  However I, and
probably most other users, find the output from this command, overwhelming
and not really directly usable. <p></p>

This is where another special shell script I wrote comes in. The "<b><code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code></b>" script will separate the
individual frames of the animation, but will also figure out exactly what IM
"<code>convert</code>" options you would need in order to re-build the
animation from those images. <p></p>

You can think of "<code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code>" as
an animation disassembler, producing a summary of the animation in terms of IM
options. <p></p>

For example, lets decode the animation example we have been using to recover
the original "<code>convert</code>" settings used to create it, as well as
individual images used...

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  gif2anim canvas_prev.gif
</code></pre></td></tr></tbody></table>
<table border="0" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td>
  <a href="http://www.imagemagick.org/Usage/anim_basics/canvas_prev.anim"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev.anim.gif" align="middle" vspace="5" hspace="0" border="0" alt="[IM Text]"></a>
</td></tr></tbody></table></td><td align="center">
    <a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_001.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_001.gif" width="100" height="100" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_002.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_002.gif" width="32" height="32" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_003.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_003.gif" width="32" height="32" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_004.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_004.gif" width="32" height="32" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_005.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_005.gif" width="32" height="32" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br></td></tr></tbody></table><p></p>

By default the "<code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code>"
script uses the same base file name for the individual images and
"<code>.anim</code>" options file. As such the animation sequence file
generated by the above command is named "<code><a href="http://www.imagemagick.org/Usage/anim_basics/canvas_prev.anim">canvas_prev.anim</a></code>", with the individual frame images
"<code><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_001.gif">canvas_prev_001.gif</a></code>" to
"<code><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_005.gif">canvas_prev_005.gif</a></code>". <p></p>

If you examine the results more closely you will see that it actually did
manage to re-create the original options I used when I first created this GIF
animation (See <a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Dispose Previous Animation</a>).  Also
while it is not important to actually generating an animation, the size, and
timings of the overlaid frames is also listed as a comment, to make it easier
to study. <p></p>

Rather than save the results to a file you can just list the animation
sequence options to the screen using a "<code>-l</code>" flag.  That is just
output the animation sequence file, rather than save it, or the individual
frame images of the animation.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code do_not_execute="">
  gif2anim -l canvas_prev.gif
</code></pre></td></tr></tbody></table>
</div><p></p>


<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">

Given a "<code>.anim</code>" file and the individual framing images,
a complementary script "<b><code><a href="http://www.imagemagick.org/Usage/scripts/anim2gif">anim2gif</a></code></b>" can be used to re-build the animation.

<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr valign="top"><td><pre><code execute="">
  anim2gif canvas_prev.anim
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_anim.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_anim.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

The  "<code><a href="http://www.imagemagick.org/Usage/scripts/anim2gif">anim2gif</a></code>" by default
will re-create the GIF animation with a "<code>_anim.gif</code>" suffix.  You
can see that the resulting "<code><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_anim.gif">canvas_prev_anim.gif</a></code>" animation generated, looks and works exactly
like the original animation.  <p></p>

This script simply replaces the special string "<code>BASENAME</code>" used in
the "animation sequence file", strips all comments, then just pass the convert
options that is left into the "<code>convert</code>" command.  In other words
it treats the above file as a type of 'convert' script with comments. <p></p>

The reason a special string was used, is because this then allows you to
specify a different base filename than the name of the "<code>.anim</code>"
file itself.  That way you can use a completely different set of frame images,
such as modified versions of the original, to recreate a different animation
from the old one.  This is very useful feature, which will used in more
complex animation processing. (See <a href="http://www.imagemagick.org/Usage/anim_mods/#append">Appending
Animations Side-By-Side</a> for an example).  <p></p>

Like "<code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code>", the "<code><a href="http://www.imagemagick.org/Usage/scripts/anim2gif">anim2gif</a></code>" script has quite a number of
useful options, to help you process and modify animations.  Some of these
options will be used later. For example see <a href="http://www.imagemagick.org/Usage/anim_mods/#append">Appending Animations</a>. <p></p>

Also as the "<code>.anim</code>" file is plain text you can use it take the
decoded images of an animation to adjust the GIF's meta-data, such as the
timings, positions, repeating sections of an animation, or adding new frames
and images to an animation. This was after all why I originally wrote the
scripts, long before I got involved with IM examples. <p></p>

For now the "<code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code>" will be
most useful for examining an animation sequence to see just what is happening,
and the timings that is being applied between frames.  <p></p>


<a name="dispose_images"></a>
<h3>Dispose Images
<font size="-1">- the GIF dispose form of the frames</font></h3>

This special "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?layers">-layers</a></code>"
method, '<code><b>Dispose</b></code>' shows what the frame should look like
<i>after</i> the time delay is finished, and the GIF dispose method has been
applied, but <i>before</i> the next frames image is overlaid. <p></p>

In other words this show exactly what the GIF "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" method setting actually
does to the frame, allowing you figure out exactly what is going wrong with
your animation. <p></p>

For example here is how each of our three <a href="http://www.imagemagick.org/Usage/anim_basics/#dispose">Dispose Method
Example Animations</a> look like after the individual frame dispose method was
applied.   Remember each of these animations consist of a 'canvas image' that
was set with a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>"  setting, then followed
by four smaller images overlaid then disposed of by the various GIF dispose
methods. <p></p>

'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' dispose animation...
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert  canvas_none.gif -layers Dispose canvas_none_dispose.gif
  gif_anim_montage canvas_none_dispose.gif canvas_none_dispose_frames.gif
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/canvas_none_dispose_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_none_dispose_frames.gif" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
</div><p></p>

'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>' dispose animation...
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert  canvas_prev.gif -layers Dispose canvas_prev_dispose.gif
  gif_anim_montage canvas_prev_dispose.gif canvas_prev_dispose_frames.gif
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_dispose_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_dispose_frames.gif" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
</div><p></p>

'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>' dispose animation...
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert  canvas_bgnd.gif -layers Dispose canvas_bgnd_dispose.gif
  gif_anim_montage canvas_bgnd_dispose.gif canvas_bgnd_dispose_frames.gif
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/canvas_bgnd_dispose_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_bgnd_dispose_frames.gif" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
</div><p></p>

If you study the above you can see exactly how each of the three GIF dispose
methods clear the animation of that frames overlaid image.  Note that the
first frame of these three animations is always set to a dispose of
'<code>None</code>' so will remain unchanged. It is the effect of the dispose
method in the later frames that is imporant. <p></p>

<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
    The "<code>-layers Dispose</code>" operation only generates the
    'coalesced' sequence of the disposal frames. It does not reset the
    disposal setting itself, and as such the result may not animate properly.
    To make the above animate correctly set all disposal methods to
    '<code>previous</code>' or '<code>background</code>' or you can optimize
    the animation, before saving.

</i></font></td></tr></tbody></table><p></p>

<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
    The look of the final frame after the GIF dispose method is normally of no
    consequence to a GIF animation, as the whole canvas is completely cleared
    before the animation repeats (loops).  If it does not 'loop' but stops
    at the end of the animation sequence, then the final frames disposal is
    not applied. <p></p>

    In other words the appearance of the last frame (after disposal) as shown
    above, or even the actual dispose setting of the last frame, does have any
    effect on a GIF animation.  IM generally sets this to same as the previous
    frame when it trys to work out an appropriate disposal method, during a <a href="http://www.imagemagick.org/Usage/anim_opt/#optframe">Frame Optimize</a> an animation.

</i></font></td></tr></tbody></table><p></p>


<a name="deconstruct"></a>
<h3>Deconstruct
<font size="-1">- report areas of frame differences</font></h3>

The traditional way in ImageMagick to optimize an animation, making the result
smaller and faster to download and animate, is to "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" its "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" form. <i>This is no
longer recommended</i>. Instead you use should use the <a href="http://www.imagemagick.org/Usage/anim_opt/#optimize">General GIF Optimizer</a>. <p></p>

This operator will take a coalesced sequence of images (the animation frames
as they actually appear when displayed), and compare the second and later
images with that of the previous image. It then replaces that image with the
smallest rectangular area of the pixels that had changed.  Any pixel change,
will count, regardless of if it is a color change (overlay) or cleared
(erased). <p></p>

This is quite simple, and for a typical <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay
Animations</a> will generate an optimal <a href="http://www.imagemagick.org/Usage/anim_opt/#frame_opt">Frame Optimization</a> for that animation. An <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay
Animations</a> animation however only use a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' dispose method only. <p></p>

For example lets take the <a href="http://www.imagemagick.org/Usage/anim_basics/#coalesce">coalesce previous animation</a>
we generated above, which happens to form a  <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay
Animation</a>, and run it though the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" operator.

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr valign="top">
<td width="80%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert  canvas_prev.gif   -coalesce     coalesce.gif
  convert  coalesce.gif     -deconstruct   deconstruct.gif
  gif_anim_montage  coalesce.gif     coalesce_frames.gif
  gif_anim_montage  deconstruct.gif  deconstruct_frames.gif
</code></pre></td></tr></tbody></table></td>
<td align="center" rowspan="2">
  <a href="./Animation Basics -- IM v6 Examples_files/deconstruct.gif"><img src="./Animation Basics -- IM v6 Examples_files/deconstruct.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr><tr><td align="center"><nobr>
  <a href="./Animation Basics -- IM v6 Examples_files/coalesce_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/coalesce_frames.gif" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
  <img src="./Animation Basics -- IM v6 Examples_files/space.gif" align="middle" width="20" height="20" alt="==&gt;">
<br><img src="./Animation Basics -- IM v6 Examples_files/right.gif" align="middle" width="20" height="20" alt="==&gt;">
  <a href="./Animation Basics -- IM v6 Examples_files/deconstruct_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/deconstruct_frames.gif" align="middle" vspace="0" hspace="0" border="0" alt="[IM Output]"></a>
</nobr></td></tr></tbody></table><p></p>

A 'previous dispose animation' if you remember clears each frame to the last
non-previous disposed frame, in this case the initial background canvas.

As you can see "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" returned the area that changed from one coalesced
frame to the next.  Resulting in an optimized <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay
Animation</a>, that requires no special dispose setting. <p></p>

This is nowhere near as optimal as the original hand generated animation I
started with, but is useful in itself. <p></p>

<table cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td align="justify">
Unfortunately "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" has absolutely no understanding of the GIF animation
"<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" settings.
Consequently if you try this on an animation that clears pixels from one frame
to the next, such as the '<a href="http://www.imagemagick.org/Usage/anim_basics/#background">background disposed</a>'
animation we created above (and shown left), it will fail badly.
</td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/canvas_bgnd.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_bgnd.gif" width="100" height="100" align="right" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table>


<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr valign="bottom"><td width="100%" align="justify">

Here we take the just shown animation, and run it though a "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" and "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" cycle.

<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert canvas_bgnd.gif  -coalesce  -deconstruct  deconstruct_erase.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/deconstruct_erase.gif"><img src="./Animation Basics -- IM v6 Examples_files/deconstruct_erase.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

As you can see "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>", slowly destroys the animation. Basically "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" is designed to
simply find the differences between image layers.  It was never designed to
correctly optimize animations, and will fail for animations that need to use
various disposal techniques to clear (erase or make transparent) previously
overlaid pixels. <p></p>


<a name="compare"></a>
<h3>Frame Comparisons
<font size="-1">- more detailed comparing of frames</font></h3>

With IM v6.2.6-2, a number of extra GIF frame comparison methods were added.
<p></p>

These were needed internally for proper optimization of animations, but was
deems useful enough to make them available to the command line and other API
interfaces. <p></p>


<a name="compareany"></a>
<h4>Compare_Any</h4>

The "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?layers">-layers</a></code>" method
'<code><b>CompareAny</b></code>' is actually exactly the same as "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>".  In fact the
"<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>"
operator is only a functional alias for the '<code>CompareAny</code>' method.
<p></p>

Again lets look at the actual image results of a 'deconstruct' or
'<code>CompareAny</code>' of the '<a href="http://www.imagemagick.org/Usage/anim_basics/#background">background
disposed</a>' animation.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert canvas_bgnd.gif  -coalesce  canvas_bgnd_coal.gif
  gif_anim_montage canvas_bgnd_coal.gif canvas_bgnd_coal_frames.gif

  convert canvas_bgnd_coal.gif  -layers CompareAny   compare_any.gif
  gif_anim_montage compare_any.gif compare_any_frames.gif
</code></pre></td></tr></tbody></table>
<nobr>
  <a href="./Animation Basics -- IM v6 Examples_files/canvas_bgnd_coal_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_bgnd_coal_frames.gif" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
  <img src="./Animation Basics -- IM v6 Examples_files/space.gif" align="middle" width="20" height="20" alt="==&gt;">
<br><img src="./Animation Basics -- IM v6 Examples_files/right.gif" align="middle" width="20" height="20" alt="==&gt;">
  <a href="./Animation Basics -- IM v6 Examples_files/compare_any_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/compare_any_frames.gif" align="middle" vspace="0" hspace="0" border="0" alt="[IM Output]"></a>
</nobr></div><p></p>

As you can see the second and later images, is the minimal rectangular area
that contains all the pixels that have changed, whether it is an overlay of a
new pixel color, or a clearing of an old pixel to transparency. <p></p>

<a name="compareclear"></a>
<h4>Compare_Clear</h4>

The "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?layers">-layers</a></code>" method
'<code><b>CompareClear</b></code>' will show the smallest rectangular area
that contains all the pixels that needed to be cleared from one frame to the
next.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="" err="/dev/null">
  convert canvas_bgnd_coal.gif -quiet -layers CompareClear compare_clear.gif
  gif_anim_montage compare_clear.gif compare_clear_frames.gif
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/compare_clear_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/compare_clear_frames.gif" align="middle" vspace="0" hspace="0" border="0" alt="[IM Output]"></a>
</div><p></p>

Notice that as no pixels were cleared between the first and second frame, a
special <a href="http://www.imagemagick.org/Usage/crop/#crop_missed">Missed Image</a> was generated. The
"<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?quiet">-quiet</a></code>" setting was used
to tell IM not to give any warning about this image. <p></p>

If all the later frames all become 'missed' images, then the GIF animation
never clears pixels, and the animation can be classed as a <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animation</a>. <p></p>

<a name="compareoverlay"></a>
<h4>Compare_Overlay</h4>

The last "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?layers">-layers</a></code>"
comparison method, '<code><b>CompareOverlay</b></code>', returns the area of
pixels that were overlaid (added or changed in color, but not cleared) since
the previous frame.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert canvas_bgnd_coal.gif  -layers CompareOverlay  compare_overlay.gif
  gif_anim_montage compare_overlay.gif compare_overlay_frames.gif
</code></pre></td></tr></tbody></table>
  <a href="./Animation Basics -- IM v6 Examples_files/compare_overlay_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/compare_overlay_frames.gif" align="middle" vspace="0" hspace="0" border="0" alt="[IM Output]"></a>
</div><p></p>

This is similar to the special IM specific '<a href="http://www.imagemagick.org/Usage/compose/#changemask">ChangeMask</a>" Alpha Composition Method. However, that returns just the
pixels that change the image, rather than the rectangular area that was
changed.  See also <a href="http://www.imagemagick.org/Usage/anim_opt/#opt_trans">Transparency
Optimization</a>. <p></p>


<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
    None of the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?layers">-layers</a></code>"
    comparison methods, nor the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" operator, look at or modify the image GIF
    dispose method that is used.  The results is just a list of images, and
    not expected to be used as animations themselves.
</i></font></td></tr></tbody></table><p></p>

<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/expert.gif" width="23" height="26"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="17" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
    While the operators are designed to work with a coalesced image sequence,
    they will accept a non-coalesced sequence of image layers, without
    producing an error. <p></p>

    In this case each frame is overlaid onto the previous overlaid frames
    using a '<code><a href="http://www.imagemagick.org/Usage/compose/#copy">Copy</a></code>' alpha
    composition method, before the frames are compared.  This alpha
    composition method ensures that any transparency in a layer will also be
    added to the destination image. Without this the above would not find
    pixels that get cleared to transparency in a coalesced image sequence.
    <p></p>

    Note that this is different to the more normal '<code><a href="http://www.imagemagick.org/Usage/compose/#over">Over</a></code>' composition method that the
    "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" operator
    would use for handling the 'dispose/overlay' cycle needed to display
    a GIF animation. <p></p>

</i></font></td></tr></tbody></table><p></p>

<hr><!-- ---------------------------------------------------------------- -->

<a name="types"></a>
<h2>Types of Animations</h2>

Most GIF animations you find fall into some basic types of animation.  Knowing
about these types allows you understand how that animation is being displayed
from one frame to another, and can allow you to take shortcuts in how you
handle and modify the animation. <p></p>

<a name="coalesced"></a>
<h3>Coalesced Animations</h3>

A '<b>Coalesced Animation</b>' is basically an image sequence that shows what
an animation should look like when displayed to an user after each
'dispose/overlay' cycle.  The images are basically as you would see them if
you were looking at an actual 'film strip' of the animation.  It is the
simplified and completely un-optimized form of any animation. <p></p>

This naming convention is from the name of the IM "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" operator that is used
to convert GIF disposal animations, into an un-optimized 'Coalesced Animation'.
<p></p>

Most video formats (MPEG, AVI etc) are actually also 'Coalesced Animations' by
their very nature.  However these also tend not to have any transparent
pixels, and generally have a constant time delay between the frames of the
animation.  A coalesced GIF animation however can have transparent pixels, and
widely varying time delays from immediate '0' delays, to very fast, or very
very very slow. <p></p> <p></p>

Any GIF disposal setting in a coalesced animation does not have any meaning,
however the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" operator will set the disposal appropriately so the
resulting image sequence can still work as a valid GIF animation. <p></p>

Video formats which always replaces every pixel from one frame to the next can
generally just use a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' or '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">Undefined</a></code>'  GIF disposal setting. <p></p>

Here is an example of an animation that is also by its nature a Coalesced
Animation, plus a "<code><a href="http://www.imagemagick.org/Usage/scripts/gif_anim_montage">gif_anim_montage</a></code>" display of the animations individual frames.

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr valign="middle"><td width="10%">
</td><td width="80%" align="center">
  <a href="./Animation Basics -- IM v6 Examples_files/smoke_skull_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/smoke_skull_frames.gif" width="684" height="296" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
</td><td align="center">
  <a href="./Animation Basics -- IM v6 Examples_files/smoke_skull_anim.gif"><img src="./Animation Basics -- IM v6 Examples_files/smoke_skull_anim.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

Most animations that do not contain, or use, transparency, and which animate
the entire canvas, are usually saved and distributed as Coalesced Animations.
<p></p>


<a name="overlay"></a>
<h3>Overlay Animations</h3>

An '<b>Overlay Animation</b>' is one in which each frame of an animation only
overlays new pixels to the animation currently displayed.  In other words at
no point in the animation does it need to clear a pixel to transparency. The
individual frames can contain transparency, either as a background, or as part
of its optimization, but it never clears a pixel back to transparency. <p></p>

Of course if no transparency is used at all, then the animation is guaranteed
to be able to be turned into a simple Overlay Animation. <p></p>

This is probably the simplest type of <a href="http://www.imagemagick.org/Usage/anim_basics/#frame_opt">Frame
Optimized</a> animation, and one that requires no special handling by clients.
Each frame that is shown to the user can be viewed as simply as 'flattened'
image of all the previous frames. <p></p>

Any animation that only uses a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' GIF
disposal method is an 'Overlay Animation'. The last example for instance is
not only a '<a href="http://www.imagemagick.org/Usage/anim_basics/#coalesced">Fully Coalesced Animation</a>' but also a
'Overlay Animation', though not all such 'Fully Coalesced Animations' are
'Overlay Animations'. <p></p>

You can test if an animation can become an overlay animation by using the
'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#compareclear">CompareClear</a></code>' layers method on a <a href="http://www.imagemagick.org/Usage/anim_basics/#coalesce">Coalesced</a> animation, and checking if all the second and
later images are 'missed images'. That is no pixel needed to be cleared or
erased from one frame to the next. <p></p>

In fact if an animation can become an overlay animation, without modification,
then the IM "<code><a href="http://www.imagemagick.org/Usage/anim_basics/#coalesce">coalesce</a></code>" operator will
only use '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' disposal methods for all the
frames.  If this is not the case then "<code><a href="http://www.imagemagick.org/Usage/anim_basics/#coalesce">coalesce</a></code>" will have used '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>' disposal for at least some of the frames.  This then
gives you with another test for 'overlay only' capability. <p></p>

Overlay animations can use transparency, but they do not have any moving parts
on a transparent background.  For example, the animation of a hand drawn
letter 'K', is an overlay animation, as each part only adds or changes
existing parts on a transparent background.  It never adds new transparency to
the resulting image (except as part of the first frame).

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr valign="middle"><td width="10%">
</td><td width="80%" align="center">
  <a href="./Animation Basics -- IM v6 Examples_files/script_k_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_frames.gif" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
</td><td align="center" rowspan="3">
  <a href="./Animation Basics -- IM v6 Examples_files/script_k.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k.gif" width="53" height="54" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

  <a href="./Animation Basics -- IM v6 Examples_files/dl_world_anim.gif"><img src="./Animation Basics -- IM v6 Examples_files/dl_world_anim.gif" width="110" height="60" align="right" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>

That is not to say an moving object can't be handled by an overlay animation,
it just means you need a non-transparent background so you can also 'erase'
the old positions of the moving parts without needing transparency.  For
example look at the frames of this "download the world into a folder"
animation... <br clear="all">

<div align="center">
  <a href="./Animation Basics -- IM v6 Examples_files/dl_world_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/dl_world_frames.gif" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
</div><p></p>

Of course by needing to 'erase' old parts by overlay the original background
means that overlaid sub-images are generally bigger, and hence a generally
larger GIF animation file size. <p></p>

Unfortunately using the IM's <a href="http://www.imagemagick.org/Usage/anim_opt/#optframe">Optimize
Frame</a> operator, can, and most probably will, turn a 'Coalesced Overlay
Animation' into into something that is not a 'Overlay Animation', in its
attempt to find smaller GIF file size. <p></p>

However by using <a href="http://www.imagemagick.org/Usage/anim_basics/#deconstruct">Deconstruct</a> on the animation
instead of using <a href="http://www.imagemagick.org/Usage/anim_opt/#optframe">Optimize Frame</a>, you can
ensure the animation remains a simple 'Overlay Animation', but only if the
animation is really a 'Overlay Animation'.  If the animation isn't a 'Overlay
Animation', then <a href="http://www.imagemagick.org/Usage/anim_basics/#deconstruct">Deconstruct</a> operation can go
badly wrong (See <a href="http://www.imagemagick.org/Usage/anim_basics/#deconstruct">Deconstruct</a> above). <p></p>

With some human skill you can still optimize an overlay animation better, for
example using <a href="http://www.imagemagick.org/Usage/anim_opt/#splitting">Split Frame Updates</a>, and
applying some form of <a href="http://www.imagemagick.org/Usage/anim_opt/#compress_opt">Compression
Optimization</a> without destroying the 'Overlay Only' requirement of the
animation.  <p></p>

Typically 'Overlay Animations' display no transparency at all (they can use
it as part of optimization, but they don't display it).  And if no
transparency is displayed, then the animation is guaranteed to be a 'Overlay
Animation'. <p></p>

Why is 'Overlay Animations' so important? Because there is software out there
that are limited to this type of animation.  It is much simplier to handle as
only overlay is performed without need to handle transparency, or save the
previous frame to handle GIF disposal methods.  Such software is rare but does
exist.  <p></p>


<a name="cleared"></a>
<h3>Cleared Frame Animations</h3>

When an animation only uses just '<a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a>' or '<a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a>' GIF disposal, you get a very special type
of animation. <p></p>

Note that if only '<a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a>' disposals is used,
all the frames of an animation are displayed then cleared before the next
frame is displayed.  Also when only '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>' are used, the animation is always returned to the
initial cleared canvas before the next frame is displayed, resulting in the
same effect.  Same happens if you only use a mix of those two disposal
settings. <p></p>

That is, animations that only uses these disposal methods will have frames
that are complete copies of what is to be displayed.  That is, the frame
contains everything that will be displayed to the user at that point in time.
<p></p>

That is not to say that the animation is a '<a href="http://www.imagemagick.org/Usage/anim_basics/#coalesced">Fully
Coalesced Animation</a>'. As the sub-frame may be a lot smaller than the
virtual canvas area of the animation, but everything outside that frame will
be regarded as transparent (or background), containing nothing of importance.
<p></p>

For example take a look at this running bunny animation...

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr valign="middle"><td width="10%"></td>
<td width="80%" align="center">
  <a href="./Animation Basics -- IM v6 Examples_files/bunny_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/bunny_frames.gif" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
</td><td align="center">
  <a href="./Animation Basics -- IM v6 Examples_files/bunny_anim.gif"><img src="./Animation Basics -- IM v6 Examples_files/bunny_anim.gif" width="110" height="64" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

Note that each and every sub-frame is the complete image that is displayed.
No more, no less.  Also notice that none of the frames actually needs to use
the whole virtual canvas of the animation.  And finally note how all the frame
disposals are set to '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>', which
for reasons you will see below is the more logical disposal setting to use.
All the disposal settings could however have been set to '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>' disposal or any mix of the two
without changing the final result.<p></p>

For want of a better name I call such an animation a '<b>Cleared Frame
Animation</b>', but I have also seen it called a 'Previous or Background
Disposal Animation'. <p></p>

The only time that an animation is not of this type is if at least one
non-blank frame in the animation used a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' or '<code>Undefined</code>' (same thing) disposal method.
<p></p>

This animation is very special, as it can handle any amount of transparency
clearing, anywhere within the animation sequence, unlike a <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animation</a>.  But it can also be overlaid onto ANY static
background image really quickly. <p></p>

To do this we need to tighten the definition of a 'Cleared Frame Animation'
slightly.  Specifically we need to make sure all the disposals are set to
'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>' (which is already the case in
our example).  If that is done, then you can just pre-pend an image (with a
zero delay) to underlay a background.  <p></p>

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr valign="bottom"><td width="100%" align="justify">

For example lets place our bunny on some grass....

<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert bunny_grass.gif bunny_anim.gif -loop 0  bunny_on_grass.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/bunny_on_grass.gif"><img src="./Animation Basics -- IM v6 Examples_files/bunny_on_grass.gif" width="120" height="80" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

As you can see this is so simple that many applications use these types of GIF
animations to add symbols or other indicators (file locks, smileys, stars,
etc) to larger objects. <p></p>

Animating such a GIF animation is also easy, as the application can just clear
the area to some simple constant background image, and overlay the next frame
in the sequence. No need to calculate disposals, or keep track of a 'previous'
display, other than the static unchanging background display. <p></p>

This is also the reason why a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>'
disposal is the preferred disposal for a <a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared Frame
Animation</a>. <p></p>

Unlike a <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animation</a> which are only a special
sub-set of GIF animations, ALL animations can be saved as a <a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared Frame Animation</a>.  Just <a href="http://www.imagemagick.org/Usage/anim_basics/#coalesce">coalesce</a> the
animation, and optionally <a href="http://www.imagemagick.org/Usage/crop/#trim">trim</a> any surrounding
transparent edges to frame optimize it, and reset the disposals.

<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code do_not_execute="">
  convert any_animation.gif -coalesce -trim \
          -set dispose previous   cleared_frame_animation.gif
</code></pre></td></tr></tbody></table>
</div><p></p>

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr valign="bottom"><td width="100%" align="justify">

You can even re-position the animation on that background...

<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert bunny_grass.gif \( bunny_anim.gif -repage 0x0+5+15\! \) \
          -loop 0  bunny_on_grass2.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/bunny_on_grass2.gif"><img src="./Animation Basics -- IM v6 Examples_files/bunny_on_grass2.gif" width="120" height="80" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>

As such a <a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared Frame Animation</a> typically consists
of a small, constantly changing or moving object on a transparent
background. These are directly usable on web pages, or as animated symbols, or
can be merged with other animations to produce much more complex animations.
<p></p>

In summery this type of animation is a good style to use in a library of
animated parts, for use in creating larger more complex animations. <p></p>

<br>

There is however a problem with adding background like this for GIF
animations.

If you look at the previous examples, you would probably have notice a
significant and disturbing pause in the fast moving animation. That is the
bunny vanished for a moment, when the animation looped, and the background
image is re-loaded. (See notes in <a href="http://www.imagemagick.org/Usage/anim_basics/#zero">Zero Delay Frames</a> )<p></p>

Though this is not a problem for applications that use this technique, for
adding animated symbols to displayed objects, as they just don't display that
'intermediate' frame, anyway. <p></p>

As such if are adding a non-transparent background to the GIF animation, then
it is generally a good idea to convert the simple <a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared
Frame Animation</a> into a <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animation</a>.  That is
add that background to every frame of the animation, rather than give an
initial canvas. <p></p>

You can do that by either, <a href="http://www.imagemagick.org/Usage/anim_basics/#coalesce">Coalescing</a> the above
animation, then deleting the <a href="http://www.imagemagick.org/Usage/anim_basics/#zero">Zero Delay</a> Background frame,
OR <a href="http://www.imagemagick.org/Usage/anim_mods/#composite">Layer Composite</a> the original
animation onto a <a href="http://www.imagemagick.org/Usage/anim_mods/#background">Static Background</a>.
<p></p>

For example...
<div align="center">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
  convert bunny_grass.gif \( bunny_anim.gif -repage 0x0+5+15\! \) \
          -coalesce -delete 0 -deconstruct -loop 0  bunny_bgnd.gif
  gif_anim_montage  bunny_bgnd.gif  bunny_bgnd_frames.gif
</code></pre></td></tr></tbody></table></td><td>
  <a href="./Animation Basics -- IM v6 Examples_files/bunny_bgnd.gif"><img src="./Animation Basics -- IM v6 Examples_files/bunny_bgnd.gif" width="120" height="80" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
  <a href="./Animation Basics -- IM v6 Examples_files/bunny_bgnd_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/bunny_bgnd_frames.gif" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</div><p></p>

Now that all the frames are displayed equally well, no pause can be seen as
the background is reset.  The animation however is now an <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animation</a> with background being 're-drawn' due to the movement of
the animation object, as such it is probably a bit larger in file size. <p></p>

See <a href="http://www.imagemagick.org/Usage/anim_opt/#opt_trans">Transparency Optimization</a> for
a continuation of the optimization of the above result. <p></p>


<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
    The IM forum member <a href="http://www.imagemagick.org/Usage/forum_link.cgi?u=3499">el_supremo</a>,
    Pete, has contributed a MagickWand equivelent script, <a href="http://members.shaw.ca/el.supremo/MagickWand/bunny.htm">Cleared
    Frame onto Background example</a>. <p></p>
    
    This example is also discussed in detail in the IM Forum <a href="http://www.imagemagick.org/Usage/forum_link.cgi?f=6&amp;t=20472">Creating a Cleared Frame GIF
    Animation in the MagickWand</a>. <p></p>

</i></font></td></tr></tbody></table><p></p>


<a name="mixed"></a>
<h3>Mixed Disposal Animations
<font size="-1">- multi-background animations</font></h3>

There is nothing preventing you from mixing the various disposal methods in a
single GIF animation.  If fact adding a background to a <a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared Frame Animation</a>, does exactly that. <p></p>

Using mixing disposal methods not so simple for us humans, but doing so can
allow you to generate some very complex animated displays.  In general they
are created as part of automatic <a href="http://www.imagemagick.org/Usage/anim_opt/#frame_opt">Frame
Optimization</a> for a particular animation. <p></p>

Just remember the result will not be directly usable as the previous animation
types for specific purposes.  In fact do not be surprised if some GIF handling
programs, just do not handle a 'Mixed Disposal Animation' properly.  That
includes some of the GIF optimizers available. <p></p>

A typical example of a 'Mixed Disposal Animation' is a small moving object
that causes some semi-permanent but temporarilly static change in the
animations background.  A ball hitting a lever would be one example.  <p></p>

<pre><i>Simple Example wanted</i></pre>

Similarly animations involving two very small moving objects on a larger
transparent display can only be optimized well by mixing up the disposal
techniques, so that each object is moved using separate animation frames. <p></p>

<pre>FUTURE,
A more complex animation for study.
 * Start with a semi-transparent canvas
 * run a little 'previous' disposal
 * leave one frame as a new 'canvas'
 * more previous animations
 * erase that 'addition' using a 'background' disposal set as new canvas
 * continue back to start point.
This animation should thoroughly test out not only IM disposal methods
but also various browser disposal methods.
</pre>


<i>If you like to contribute an IM example of such an animation you can get
your name, and home page link here!</i> <p></p>

<hr><!-- ---------------------------------------------------------------- -->

<a name="loop"></a>
<h2>The End of the Loop
<font size="-1">- when an animation stops</font></h2>

It is often regarded as a good idea not to make animations loop forever, as
client machines have to continually work while the animation is still
animating.  As such it is a good idea to think about how many times your
animation actually loops. <p></p>

Basically..
<div align="center"><b>
             Add a loop limit to your animations (if practical)
</b></div><p></p>

This is especially the case for large animations used as a logo at the top of
a web page.  Depending on the overall time for which an animation runs, 10 to
30 loops is usually enough for large logos.  And you should add a loop limit
for all such animations, to be kind to your users. <p></p>

A "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?loop">-loop</a></code>" save setting of 0,
means to loop forever.  This is typically what is used, and that is okay, for
small animations.  Some browsers however enforce a stop when an animation
reaches some internal loop limit (often 256 loops). <p></p>

For IM Examples I have generally used a '0' "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?loop">-loop</a></code>" save setting, meaning 'loop
forever', because the animations can appear anywhere on a page.  That means it
may be some time between when the user loaded a page to when they finally look
at and read about a particular GIF animation.  If I did use a smaller number
of 'loops', the animation would no longer be doing what it should be
demonstrating, loosing its effectiveness. <p></p>

For large animations on top level flash pages, a "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?loop">-loop</a></code>" of '1', the normal GIF
animation default, can be used.   This means run though the animation once
only and then stop. <p></p>

Which brings us to an all important question..  <b>Stop where?</b> <p></p>

Some browsers, like the old "<code>Netscape</code>" browser, re-displayed the
first frame of the animation.  Most modern browsers however will just stop
on the last frame, ignoring that frames useless <a href="http://www.imagemagick.org/Usage/anim_basics/#dispose">dispose</a>
setting. <p></p>

What a specific application does however is up to the application as there is
no true standard. Actually even the use of the 'loop' meta-data, is itself
non-standard, just something that the old "<code>Netscape</code>" browser
implemented, and all later browsers copied. <p></p>

Because of this, if there is some specific frame that you want your animation
to stop on, say the frame with your company name or logo on it, then it is a
good idea to make that frame both the first and last frame of an animation One
of those frames however should be given a 'zero delay', so as not to effect
the overall loop time length of the animation. <p></p>

So just to summarize...
<div align="center"><b>
      If loop limited, add the 'stop' frame as BOTH first and last frames.
</b></div><p></p>

<hr><!-- ---------------------------------------------------------------- -->

<a name="zero"></a>
<h2>Zero Delay Intermediate Frames</h2>

We have already seen use of a frame that has a 'zero delay', with regard to
a <a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared Frame Animations</a>.  I also used them to
explain <a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous and Background Disposals</a>. <p></p>

These special frames are actually a lot more common then people would probably
think. They represent not only methods to prepend a background 'canvas' to an
animation (such as I have used them for above).  But they are also a must for
some of the more complex <a href="http://www.imagemagick.org/Usage/anim_opt/#opt_frame">Frame
Optimization</a> techniques, such as <a href="http://www.imagemagick.org/Usage/anim_opt/#doubling">Frame
Doubling</a> and <a href="http://www.imagemagick.org/Usage/anim_opt/#splitting">Splitting Frame
Updates</a>. <p></p>

Another (very old pre-PNG format) usage was to allow you to create static GIF
images that contained more than the 256 color limit!  That is each frame
provides 256 colors, and the next frame the next set of 256 colors, all with
zero delay and no looping at the end.  Thanks to <a href="http://www.imagemagick.org/Usage/forum_link.cgi?u=23894">TLUL</a> in the discussion <a href="http://www.imagemagick.org/Usage/forum_link.cgi?f=1&amp;t=22855">Creating unquantized GIFs</a> for
pointing this out. <p></p>

These '<i>zero delay intermediate frames</i>' are not meant to be displayed to
an user. They are just used to create special effects in GIF images that are
otherwise not posible or better optimized than you would get without them.
<p></p>

In summary...
<div align="center"><b>
             Zero Delay Frames are Intermediate Frames,
<br>         They are not meant to be visible to users.
</b></div><p></p>

ImageMagick not only will create such frame in animations as part of its
automatic '<a href="http://www.imagemagick.org/Usage/anim_opt/#optimizeplus">OptimizePlus</a>', but also
provides a way to remove them using the '<a href="http://www.imagemagick.org/Usage/anim_opt/#removezero">RemoveZero</a>' layers method. <p></p>

Watch out for them, as they will often complicate your handling of Animations.
<p></p>

Okay so they are important, what of it?

Because many applications don't like them, or incorrectly handle them.  They
consider 'Zero Delay Frames' as a bad thing, even when you purposely add them
to animations, for some reason or another.  <p></p>

Here is summary of applications that I know about or have been told,
'do the wrong thing'... <p></p>

<table align="center">
<tbody><tr valign="top"><td><b>Gimp</b>
</td><td>Will not save a 'Zero Delay Frame', they always add a minimal time
    delay to any frame that has a zero time delay. :-( <br>&nbsp;

</td></tr><tr valign="top"><td><b>FireFox</b>
</td><td>Will give a slight non-zero pause on such frames.  This presumably is so
    that animations that have no time delays at all, do use up all the
    computers CPU cycles.  But "<code>firefox</code>" still doesn't relax that
    restriction if an animation has an overall non-zero display time.
    <br>&nbsp;

</td></tr><tr valign="top"><td><b>Internet Explorer</b>
</td><td>Has a minimum time delay of 6 centi-seconds, and ignores any delay smaller
    than this. <p></p>

    Internet Explorer version 8 also fails (immediately restarts the loop) if
    any image frame extends beyond the animation bounds set by the first
    frame.  This I would class as a major bug. <p></p>

</td></tr></tbody></table><p></p>

On the other hand ImageMagick '<a href="http://www.imagemagick.org/Usage/anim_opt/#removezero">RemoveZero</a>' layers method does do the right thing and will NOT remove any
frame if ALL the images have a 'zero time delay'.  In fact this layers method
will give a warning if it sees an animation with no time delays at all. <p></p>

This brings us to another rule-of-thumb...
<div align="center"><b>
      Never save a GIF (looping) animation that has no 'delays' at all
</b></div><p></p>

Doing so is very bad practice, and the reason most of the above 'buggy'
applications, do what they do, rather than what they should.  Complain to the
owners if you see them. <p></p>

Also complain to application developers, so that they handle Zero delay frames
correctly.  Even if it means not displaying that frame at all, just using them
as preparation for the next frame to display.  They are after all on screen
for <i>ZERO</i> time! <p></p>

</div>
<hr><!-- ---------------------------------------------------------------- -->
<address>
Created: 24 July 2004 (sub-division of "animation") <br>
Updated: 27 February 2013 <br>
Author: <a href="https://antofthy.gitlab.io/anthony.html">Anthony Thyssen</a>, &lt;Anthony.Thyssen@gmail.com&gt;<br>
Examples Generated with:
        <img src="./Animation Basics -- IM v6 Examples_files/version.gif" align="absmiddle" alt="[version image]"><br>
URL: <code>http://www.imagemagick.org/Usage/anim_basics/</code>
</address>
</body></html>